import axios from 'axios';
// import config from '../config.js';

const instance = axios.create({
	baseURL: '/api', // 设置新的接口域名
	headers: {
		'X-Requested-With': 'XMLHttpRequest',
		'Access-Control-Allow-Origin': '*',
		'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
	}
});
// http request 拦截器
instance.interceptors.request.use(
	config => {
		let token = window.localStorage.getItem("exhibitor_token");
		config.headers.Authorization = 'Bearer ' + token;
		// let hostname = window.location.hostname;
		if (config.params) {
			// config.params.hostname = hostname;
		} else {
			config.params = {};
		}

		return config;
	},
	err => {
		return Promise.reject(err);
	}
);
instance.interceptors.response.use(
	response => {
		//请求正常则返回
		return Promise.resolve(response)
	},
	error => {
		return Promise.reject(error)
	},
)

export default instance